<?php
/**
 * 树枝类
 * 2019年12月23日16:37:49
 */
namespace Application\Common\Composite\NoUseComposite;

class Branch
{
    protected $leafs = array();
    // 添加叶子
    public function add($leaf)
    {
        $this -> leafs[] = $leaf;
    }
    // 移除叶子
    public function remove($leaf)
    {
        foreach($this -> leafs as $k => $v){
            if($v === $leaf ){
                unset($this -> leafs[$k]);
                break;
            }
        }
    }
    // 执行叶子
    public function display($function=null)
    {
        $function=$function?:'display';
        foreach($this -> leafs as $k => $v){
            $v -> $function();
        }
        return true;
    }
}
